package com.xxadmin.usercenter.controller;

import com.xxadmin.common.util.clone.CopyUtils;
import com.xxadmin.common.vo.ResponseModel;
import com.xxadmin.common.vo.ResponseModelBuilder;
import com.xxadmin.common.web.BaseController;
import com.xxadmin.usercenter.dto.UserInfoDTO;
import com.xxadmin.usercenter.service.UserInfoService;
import com.xxadmin.usercenter.vo.request.UserInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户 Controller
 *
 * @author:chenming
 * @date:2018/9/4
 */
@RestController
@RequestMapping("/userInfo")
public class UserInfoController extends BaseController{

    @Autowired
    private UserInfoService userInfoService;

    @PostMapping("/addUserInfo")
    public ResponseModel addUserInfo(@RequestBody @Validated UserInfoVO userInfoVO){

        UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

        UserInfoDTO userInfoDTO = CopyUtils.copyBean(userInfoVO,UserInfoDTO.class);

        userInfoService.addUserInfo(userInfoDTO);

        return ResponseModelBuilder.genericSuccessResponseModal();
    }

}
